package com.ymatou.shop.ui.view.item;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.ymatou.shop.R;
import com.ymatou.shop.cache.ImageCache;
import com.ymatou.shop.model.Comment;

public class DetailCommentItemView extends FrameLayout implements ImageCache.OnIconLoadCompleteListener {
	
	private ImageView mIconImageView;
	private TextView mNameTextView;
	private TextView mContentTextView;
	
	public DetailCommentItemView(Context context) {
		super(context);
		initCommentItemView();
	}
	
	private void initCommentItemView() {
		LayoutInflater.from(getContext()).inflate(R.layout.list_detail_comment_item, this);
		
		mIconImageView = (ImageView) findViewById(R.id.icon_image);
		mNameTextView = (TextView) findViewById(R.id.name_txt);
		mContentTextView = (TextView) findViewById(R.id.content_txt);
	}
	
	public void setData(Comment item) {
		mNameTextView.setText(item.mPublishUserName);
		mContentTextView.setText(item.mContent);
		
		Drawable drawable = ImageCache.get(getContext(), item.mPublishUserLogo, this);
		if (drawable == null) {
			mIconImageView.setImageResource(R.drawable.ic_launcher);
		} else {
			mIconImageView.setImageDrawable(drawable);
		}
	}
	
	@Override
	public void onLoadComplete(String url, boolean success, Drawable drawable) {
		if (success) {
			mIconImageView.setImageDrawable(drawable);
		}
	}

}
